<!--
 * @Description: 
 * @Author: xiongkuobiao
 * @Date: 2023-02-20 15:02:24
 * @LastEditors: xiongkuobiao
 * @LastEditTime: 2023-02-20 16:37:27
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // eg:

    function add(a, b, c) {
      return a + b + c;
    }

    let kelihua = curry(add);

    function curry(fn, sum = []) {
      let length = fn.length;
      return function (...args) {
        sum = [...sum, ...args];
        if (sum.length === length) {
          return fn.apply(this, sum);
        }
        return curry(fn, sum);
      };
    }

    // console.log(kelihua(10, 20, 30));
    // console.log(kelihua(10)(20)(30));
    console.log(kelihua(10, 20)(30));
  </script>
</html>
